package com.mytaobao.main.firsttab.func.guessyoulike;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baseproject.helper.ViewHelper;
import com.baseproject.imageload.ImageLoaderUtil;
import com.mytaobao.R;
import com.tmall.wireless.tangram.structure.BaseCell;
import com.tmall.wireless.tangram.structure.view.ITangramViewLifeCycle;

/**
 * Created by hp on 2017/7/31.
 */

public class GuessYouLikeView extends LinearLayout implements ITangramViewLifeCycle {

    private LinearLayout llLikeItem;
    private ImageView ivBookCover;
    private TextView tvTitle;
    private TextView tvLikeItemMoney;
    private TextView tvPayedCount;


    public GuessYouLikeView(Context context) {
        this(context, null);
    }

    public GuessYouLikeView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GuessYouLikeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    private void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        inflate(getContext(), R.layout.view_guessyoulike, this);

        setOrientation(VERTICAL);
        setBackgroundColor(getResources().getColor(R.color.f4));
        llLikeItem = (LinearLayout)findViewById(R.id.llLikeItem);
        ivBookCover = (ImageView) findViewById(R.id.iv_cover);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvLikeItemMoney = (TextView) findViewById(R.id.tvLikeItemMoney);
        tvPayedCount = (TextView) findViewById(R.id.tvPayedCount);
    }

    @Override
    public void cellInited(BaseCell cell) {

    }

    @Override
    public void postBindView(BaseCell cell) {
//        ItemGuessYouLike itemGuessYouLike = mDataGuessYouLike.get(realPosition);
//        if(holder.getLayoutPosition() % 2 == 0) {
//            llLikeItem.setPadding(0,0, UIUtils.dip2px(3),0);
//        }

        ImageLoaderUtil.getInstance().with(getContext()).load(cell.optStringParam("coverUrl")).into(ivBookCover);
        tvTitle.setText(cell.optStringParam("title"));
        tvLikeItemMoney.setText("￥" + cell.optStringParam("price"));
        tvPayedCount.setText(cell.optStringParam("payedCount")  + "人已付款");
        ViewHelper.setPaddingFromCell(cell, this);
    }

    @Override
    public void postUnBindView(BaseCell cell) {

    }
}
